package com.lock;

import com.alibaba.fastjson.JSONObject;

public abstract class AbstractConsistency {

	private ThreadLocal<JSONObject> attributes = new ThreadLocal();

	private ConsistencyHandlers consistencyHandlers;

	//参数注入
	void setAttributes(JSONObject data) {
		attributes.set(data);
	}

	void setConsistencyHandlers(ConsistencyHandlers consistencyHandlers) {
		this.consistencyHandlers = consistencyHandlers;
	}

	//前拦截
	void before() {
		System.out.println("before.id: " + attributes.get().getString("id"));
	}

	//方法注入
	//abstract void execute();

	//后拦截
	void after() {
		System.out.println("after.id: " + attributes.get().getString("id"));
	}

	//拦截包装
	void inject() {
		before();//mongodb check
		//execute();//business
		consistencyHandlers.execute();
		after();//mongodb add
	}
}
